#pragma once
#include "../../test_type.h"
#include "../../../src/socket/UdpIoSocket.h"
#include "../../../src/socket/UdpIoClient.h"
#include <string>
#include <stdlib.h>

using namespace std;

namespace udp_client
{
	class UdpClient
	{
	public:
		UdpClient(LibTools::SOCKFAMILY::SockFamily domain, const string& ip, DWORD port, const string& local = "", DWORD localport = 0);
		virtual ~UdpClient();

		virtual bool Start() = 0;
		virtual DWORD CompleteSendMsg(size_t size, const char* msg) = 0;
		virtual DWORD CompleteReadMsg(size_t size, const char* msg) = 0;
		virtual DWORD CompleteConnectMsg(const char* msg) = 0;

		virtual bool Run();

		virtual bool NotifyExit();

		virtual void WaitStop();
	protected:
		void PostSendMsg(const char* data, size_t size);
		void PostRecvMsg(char* data, size_t size);
		void PostConnect();

		static DWORD CompleteSend(char* data, size_t size, LibTools::CSockError ec, void* invoker);
		static DWORD CompleteRead(char* data, size_t size, LibTools::CSockError ec, void* invoker);
		static DWORD CompleteConnect(LibTools::CSockError ec, void* invoker);
		static DWORD CompletePost(void* invoker);
	private:
		LibTools::CUdpIoSocket _udp;
		LibTools::CUdpIoClient _service;
	};
}
